Repository navigation
fix: raster outputs throw InvalidOperationException when Skia cannot allocate the image - #510
Merged
Merged
Conversation
…allocate the image SKSurface.Create returns null for a surface over 2,147,483,647 bytes, so WithSize(100000, 100000) or a large module pixel size made every raster output throw NullReferenceException. The builders now throw InvalidOperationException with the size, as for other layouts that cannot be drawn, and ToBitmap does the same when its copy cannot be allocated. The encode error no longer reports only a missing encoder: Skia also returns no data for an image past the encoder's limits, such as WebP above 16,383 pixels a side. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When Skia can't make the image, the raster outputs of the image builders now throw a clear exception. They used to crash with
NullReferenceException. The encode error also no longer blames a missing encoder when the real cause is that the image is too large for that format.Intent
Skia returns
nullinstead of throwing when it can't create an image, and the builders didn't check for that.SKSurface.Createreturnsnullfor any surface over 2,147,483,647 bytes, regardless of available memory.WithSizeandWithModulePixelSizecan both ask for more than that, so every raster output crashed with aNullReferenceException.SKImage.Encodereturnsnullboth when there is no encoder for the format and when the image exceeds the encoder's limits. For example, WebP accepts at most 16,383 px per side. The builder always reported "no encoder", which was misleading.API example
Changes
SymbolImageBuilderBase:nullfromSKSurface.Createnow throwsInvalidOperationException, the same exception as other layouts that can't be drawn.ToBitmapthrows the same exception whenSKBitmap.FromImagereturnsnull.nullfromSKImage.Encodestill throwsNotSupportedException, but the message now names both possible causes and the image size.InvalidOperationExceptiondocs now include "the image is too large for Skia to allocate".NotSupportedExceptiondoc on the builders and their static helpers now covers "cannot encode an image this large in it".ImageBuilderCanvasFitTest):InvalidOperationExceptionfor oversized canvases, through bothWithSizeandWithModulePixelSize, for QR, Micro QR and rMQR. Skia refuses before allocating, so the test uses no memory.qrcode-symbologies.mdgets a dated record next to the earlier note on missing encoders.🤖 Generated with Claude Code